package com.dormitory.javadormitory.controller;


import com.dormitory.javadormitory.common.Result;
import com.dormitory.javadormitory.entity.UserAccount;
import com.dormitory.javadormitory.service.WarrantyService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

@RestController
@RequestMapping("/Home")
public class WarrantyController {

//    @GetMapping("/all_user")
//    public Result getAllUserAccount(HttpServletRequest request){
//        HttpSession session = request.getSession();
//        System.out.println("用户Id："+session.getAttribute("userId"));
//        return Result.success(userAccountService.getUserAccounts());
//    }

    @Autowired
    private WarrantyService warrantyService;

    //根据id获取登录用户信息并返回
    @GetMapping("/Inquireiduser")
    public Result inquireUser(HttpServletRequest request){
        //token
        HttpSession se = request.getSession();
        //id
        String userId = (String) se.getAttribute("userId");

        //id查询用户
        UserAccount user = warrantyService.findById(userId);

        return Result.success(user);

    }

}
